home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / vbsprsrc / vbsprite.txt < prev   
Encoding:
Text File  |  1994-02-15  |  8.0 KB  |  194 lines

  1.  
  2.     VBSPRITE.DLL -- a DLL that does sprites from VB.
  3.  
  4.     USER'S MANUAL
  5.  
  6.     TABLE OF CONTENTS
  7.  
  8.         Chapter Zero:  Legal Mumbo-Jumbo
  9.         Chapter One:   What are SpriteWindows?
  10.         Chapter Two:   Where did you get that pBackgroundDIB, anyway?
  11.         Chapter Three: How do I make DIBs into Sprites?
  12.         Chapter Four:  What can I do with sprites besides create them?
  13.         Chapter Five:  How do I clean up this mess??
  14.         Chapter Six:   What are the declare statements for this DLL?
  15.         Chapter Seven: Do You Have Any Sample Code?
  16.         Chapter Eight: How Come This Can Only Be Used From VB?
  17.         Chapter Nine:  What Do I Do if it Doesn't Work?
  18.  
  19.  
  20. ------------------------------------------------------------------page break----
  21.  
  22.  
  23.         Chapter Zero: Legal Mumbo-Jumbo
  24.  
  25. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  26. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  27. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  28. PURPOSE. Copyright (c) 1993  Microsoft Corporation.  All Rights Reserved.
  29.  
  30.  
  31.         Chapter One: What are SpriteWindows?
  32.  
  33. In order for sprites to be drawn on the screen, a number of different things
  34. need to be brought together.  There needs to be a window, a bunch of sprites,
  35. and an off-screen bitmap.  The off-screen bitmap is so that we don't see
  36. flickering as sprites are redrawn.  (Think for a minute about what would happen
  37. without it and you'll see why it is needed).
  38.  
  39. The structure that does this in VBSPRITE.DLL is the SpriteWindow.  It has a
  40. handle to an hWnd (the real window), a linked list of sprites, and a handle
  41. to the off-screen bitmap.
  42.  
  43. When using sprites, the SpriteWindow must be created first.  Two calls are
  44. needed to create it.
  45.  
  46.     pSpriteWnd = CreateSpriteWindow(hWnd)
  47.  
  48. This creates the SpriteWindow with a handle to the real window it will draw to.
  49. And:
  50.     SetBackground(pSpriteWnd, pBackgroundDIB)
  51.  
  52. This sets the background DIB to the one you specify, and creates an off-screen
  53. bitmap of the same size.  By the way, all pointers are declared as VB "Long"
  54. (32-bit) variables.
  55.  
  56.  
  57.         Chapter Two: Where did you get that pBackgroundDIB, anyway?
  58.  
  59. DIBs (Device-Independent Bitmaps, more commonly known as .BMP files) are loaded
  60. by LoadDIB:
  61.  
  62.     pDIB = LoadDIB("filename.bmp")
  63.  
  64. pDIB will be NULL (i.e. 0) if LoadDIB failed for some reason.
  65.  
  66. (The sample app that comes with this DLL calls them .DIB files.  They can be
  67. created with BitEdit; PaintBrush is not recommended because it screws around
  68. with the palettes without telling you).
  69.  
  70.  
  71.         Chapter Three: How do I make DIBs into Sprites?
  72.  
  73. First of all, make the background and the sprites use the same palette.  (This
  74. makes sense, since they will all be in the same window!)  The pallette must be
  75. a 256-color (8-bit) one, for no good reason except that's how the sprite DLL
  76. is written.  The color in the upper left corner of the bitmap is assumed to be
  77. the transparency color, so make your bitmaps one pixel taller or wider if
  78. necessary.  (This does not apply to background bitmaps, which have no
  79. transparency)
  80.  
  81. Now, once you have a SpriteWindow created and a background bitmap assigned
  82. to it, create a sprite with:
  83.  
  84.     pSpriteDIB = LoadDIB("sprite.bmp")
  85.     pMySprite = CreateSprite(pSpriteWnd, pSpriteDIB, x, y, z, UPDATE_SCREEN)
  86.  
  87. The "z" coordinate here is what's called the z-order.  The z-order
  88. simply determines which sprites appear on top of which others.
  89. (Sorry, no 3-d perspective or ray-traced shadows).
  90.  
  91. Most of the Sprite calls have a parameter that tells it whether to update or
  92. not.
  93.  
  94.  
  95.         Chapter Four: What can I do with sprites besides create them?
  96.  
  97. You can: 1) move them,
  98.  
  99.     x = x + 1
  100.     SetSpritePosition pSpriteWnd, pMySprite, x, y, UPDATE_SCREEN
  101.  
  102. 2) change their DIB,
  103.  
  104.     pNewDIB = LoadDIB("newimage.bmp")
  105.     SetSpriteDIB pSpriteWnd, pMySprite, pNewDIB, UPDATE_SCREEN
  106.  
  107. 3) change their ZOrder,
  108.  
  109.     SetSpriteZOrder pSpriteWnd, pMySprite, z, UPDATE_SCREEN
  110.  
  111. 4) Make them invisible (or visible),
  112.  
  113.     SetSpriteVisible pSpriteWnd, pMySprite, False, UPDATE_SCREEN
  114.  
  115. or 5) See if the user clicked on them.
  116.  
  117.     pSpriteHit = SpriteHitTest(pSpriteWnd, mouseX, mouseY)
  118.  
  119.  
  120.         Chapter Five: How do I clean up this mess??
  121.  
  122. Generally, you delete the SpriteWindow, and then delete all the DIBs
  123. that it used, including the background DIB.  (These delete commands
  124. delete the objects in memory, not the disk files!).  You can call
  125. DeleteSprite to delete a sprite, DeleteSpriteWindow to delete
  126. a SpriteWindow, and DeleteDIB to delete a DIB.
  127.  
  128. If you deviate from this procedure, be careful: If you call
  129. DeleteSpriteWindow, don't try afterwards to delete a sprite,
  130. because DeleteSpriteWindow deletes all the sprites in that
  131. SpriteWindow automatically.  (This makes sense -- you can't
  132. reassign the sprite to a new SpriteWindow.  But you could use
  133. the DIB in another window).
  134.  
  135. On the other hand, if you delete a sprite, you do still need to delete
  136. any DIBs it used.
  137.  
  138. Consider the following situation: you drew up a musical note in a bitmap,
  139. and made it into a bunch of sprites which all dance around the screen
  140. at the same time.  (You can do this, because you can create more than
  141. one sprite from the same DIB).  One of the notes is no longer wanted
  142. so you call DeleteSprite.  DeleteSprite deletes the DIB and all of
  143. the other sprites suddenly have a big problem...  This is why
  144. DeleteSprite does not delete the DIB.
  145.  
  146.  
  147.         Chapter Six: What are the declare statements for this DLL?
  148.  
  149. const UPDATE_SCREEN = 1
  150. const NO_UPDATE = 0
  151.  
  152. Declare Function CreateSpriteWindow Lib "VBSPRITE.DLL" (ByVal hWnd As Integer) As Long
  153. Declare Sub DeleteSpriteWindow Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long)
  154. Declare Function LoadDIB Lib "VBSPRITE.DLL" (ByVal filename As String) As Long
  155. Declare Sub DeleteDIB Lib "VBSPRITE.DLL" (ByVal pDIB As Long)
  156. Declare Sub SetBackground Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pDIB As Long, ByVal bUpdate As Integer)
  157. Declare Function CreateSprite Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprDib As Long, ByVal initx As Integer, ByVal inity As Integer, ByVal initz As Integer, ByVal bRedraw As Integer) As Long
  158. Declare Sub DeleteSprite Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprite As Long)
  159. Declare Function SpriteHitTest Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal x As Integer, ByVal y As Integer) As Long
  160. Declare Sub SetSpritePosition Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprite As Long, ByVal x As Integer, ByVal y As Integer, ByVal bUpdate As Integer)
  161. Declare Sub SetSpriteZOrder Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprite As Long, ByVal z As Integer, ByVal bUpdate As Integer)
  162. Declare Sub SetSpriteDIB Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprite As Long, ByVal pSprDib As Long, ByVal bUpdate As Integer)
  163. Declare Function GetDIBWidth Lib "VBSPRITE.DLL" (ByVal pDIB As Long) As Long
  164. Declare Function GetDIBHeight Lib "VBSPRITE.DLL" (ByVal pDIB As Long) As Long
  165. Declare Sub RepaintSpriteWindow Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long)
  166. Declare Sub SetSpriteVisible Lib "VBSPRITE.DLL" (ByVal pSpriteWnd As Long, ByVal pSprite As Long, ByVal bVisible As Integer, ByVal bUpdate As Integer)
  167.  
  168.         Chapter Seven: Do You Have Any Sample Code?
  169.  
  170. Yes: SPRDEMO.MAK is a VB project that demonstrates use of VBSPRITE.DLL.
  171.  
  172. There are 3 sprites, and they all act differently to show off different
  173. things.  Nell (the girl) just sits there until you grab her with the
  174. mouse and drag her around.  The sun/moon sprite bounces off the bottom
  175. of the screen.  Every second or so, it changes from sun to moon, or
  176. moon to sun, and it loses energy on each bounce.  When you click it,
  177. it gives it a boost and it starts bouncing higher.  Finally, the duck
  178. cycles rapidly through four bitmaps.  When you click it, it falls down
  179. to the bottom of the screen.  That should show pretty well how a VB
  180. program can control the behavior of sprites.
  181.  
  182.  
  183.         Chapter Eight: How Come This Can Only Be Used From VB?
  184.  
  185. Actually, anyone can use it.
  186.  
  187.  
  188.         Chapter Nine: What Do I Do if it Doesn't Work?
  189.  
  190. Send email to: a-wayner@microsoft.com.
  191.  
  192. This manual was written entirely using Microsoft(R) Notepad[tm].
  193.  
  194.